package com.example.wechat;

import android.content.Context;
import androidx.annotation.NonNull;
import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory;
import com.bumptech.glide.load.engine.cache.LruResourceCache;
import com.bumptech.glide.module.AppGlideModule;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.load.DecodeFormat;
import com.bumptech.glide.Glide;
import com.bumptech.glide.Registry;

@GlideModule
public final class MyGlideModule extends AppGlideModule {
    @Override
    public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {
        // 设置内存缓存大小
        int memoryCacheSizeBytes = 1024 * 1024 * 20; // 20MB
        builder.setMemoryCache(new LruResourceCache(memoryCacheSizeBytes));
        
        // 设置磁盘缓存大小
        int diskCacheSizeBytes = 1024 * 1024 * 100; // 100MB
        builder.setDiskCache(new InternalCacheDiskCacheFactory(context, diskCacheSizeBytes));
        
        // 设置图片加载质量
        builder.setDefaultRequestOptions(
            new RequestOptions()
                .format(DecodeFormat.PREFER_RGB_565)
                .disallowHardwareConfig()
        );
    }
    
    @Override
    public void registerComponents(Context context, Glide glide, Registry registry) {
        // 注册自定义组件
        super.registerComponents(context, glide, registry);
    }
} 